const state = {
	userinfo: uni.getStorageSync('userinfo') || {}  
}
const mutations = {
	SET_USERINFO(state, data) {
		state.userinfo = data;
	}
}

const actions = {
	async login({
		commit
	}, data) {
		let result = await uni.$u.http.post('/user/login', {
			...data
		});
		if (result.data.code === 200) {
			commit('SET_USERINFO', result.data.userinfo);
			uni.setStorageSync('userinfo',result.data.userinfo);
			return result.data.code
		} else {
			return result.data.code
		}
	},
	async getUserInfo({commit},id){
		let result = await uni.$u.http.get('/user/info',{params:{id}})
		if (result.data.code === 200) {
			commit('SET_USERINFO', result.data.userinfo);
			uni.setStorageSync('userinfo',result.data.userinfo);
			return result.data.code
		} else {
			return result.data.code
		}
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
